package com.webtest.mvctest2.dao.factory;

import com.webtest.mvctest2.dao.CustomerDao;
import com.webtest.mvctest2.dao.impl.CustomerDaoJdbcImpl;
import com.webtest.mvctest2.dao.impl.CustomerDaoXmlImpl;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/7/29 13:34
 */
public class CustomerDaoFactory {
    private Map<String, CustomerDao> daos = new HashMap<>();
    private String type = null;

    private CustomerDaoFactory() {
        daos.put("jdbc", new CustomerDaoJdbcImpl());
        daos.put("xml", new CustomerDaoXmlImpl());
    }

    public static CustomerDaoFactory getInstance() {
        return CustomerDaoFactoryHolder.instance;
    }

    public void setType(String type) {
        this.type = type;
    }

    public CustomerDao getCustomerDAO() {
        return daos.get(type);
    }

    private static class CustomerDaoFactoryHolder {
        private static CustomerDaoFactory instance = new CustomerDaoFactory();

    }
}
